package com.lsh.oms.core.service.asynservice;

import com.google.common.eventbus.AsyncEventBus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.Executors;

/**
 * Project Name: lsh-payment
 * Created by miaozhuang
 * Date: 16/12/22
 * 北京链商电子商务有限公司
 * Package com.lsh.payment.core.service.AsyncService
 * desc:异步处理类
 * @author peter
 */
@Component
@Lazy(value = false)
public class OmsEventBus {

    private static AsyncEventBus asyncEventBus;

    @Autowired
    private List<IEventListener> eventListeners;

    @PostConstruct
    public void init() {
        asyncEventBus = new AsyncEventBus(Executors.newFixedThreadPool(10));
        for(IEventListener eventListener : eventListeners){
            asyncEventBus.register(eventListener);
        }
    }

    public static void post(Object obj){
        asyncEventBus.post(obj);
    }
}
